<include file="public/header" />
<style>
    .cla{
        text-align: left;padding-left: 0px;margin-left: 0px;
        width: 100%;
    }

</style>

<body style="margin-top: 20px;">

<form class="layui-form" action="">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">搜索选择品牌</label>
            <div class="layui-input-inline">
                <select name="cate_id" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                    <foreach name="category" item="vo">

                        <empty name="vo.child">
                            <option value="{$vo.id}" {vo.id == $info.cate_id ?'selected':'' }>{$vo.name}</option>
                            <else/>
                            <optgroup label="{$vo.name}">
                                <foreach name="$vo.child" item="vv">
                                    <option value="{$vv.id}" {vv.id == $info.cate_id ?'selected':'' }>{$vv.name}</option>
                                </foreach>
                            </optgroup>
                        </empty>

                    </foreach>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题:</label>
        <div class="layui-input-block">
            <input class="layui-input" name="name" style="width: 350px !important;" value=""></input>
        </div>
    </div>

    <div class="layui-form-item">

        <label class="layui-form-label">上传封面</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn"  id="test5"><i class="layui-icon"></i>上传封面</button>
        </div>
    </div>
    <input type="hidden" id="thumbs" name="thumb" value="">
    <div class="layui-form-item" id="thumb" style="display: none">
        <label class="layui-form-label">预览图</label>
        <div class="layui-input-block">
            <img id="prev_img" style="width: 200px;height: 200px;" src="">
        </div>
    </div>

    <div class="layui-form-item">

        <label class="layui-form-label">相册：</label>
        <input type="hidden" name="album" class="multiple_show_img" value="">
        <div class="layui-upload" style="padding-left: 100px;">
            <button type="button" class="layui-btn" id="multiple_img_upload"><i class="layui-icon"></i>上传:</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                预览：
                <div class="layui-upload-list" id="div-slide_show"></div>
            </blockquote>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
            <input type="number" name="sort"  lay-verify="required"  value="{$info.sort}" style="width: 50px !important;" autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">价格<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
            <input type="number" name="price"  lay-verify="required"  value="{$info.price}" style="width: 150px !important;" autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">优惠价<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
            <input type="number" name="discount_price"  lay-verify="required"  value="{$info.discount_price}" style="width: 150px !important;" autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">简介<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
            <textarea name="introduce" class="layui-textarea"  style="width: 500px;"  autocomplete="off" placeholder="" ></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">简介<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
            <textarea id="demo" name="content" style="display: none;"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">库存<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
            <input type="number" name="stock"  lay-verify="required"  value="{$info.sort}" style="width: 50px !important;" autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">服务<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
            <foreach name="server" key="key" item="item">
                <input type="checkbox" name="server_id_json[]" value="{$item.id}" title="{$item.name}">
            </foreach>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开启固定提成</label>
        <div class="layui-input-block">
            <input type="radio" name="fixed_income" checked onclick="openfiexdincoe(0)" value="0" title="否" >
            <input type="radio" name="fixed_income" onclick="openfiexdincoe(1)"  value="1" title="是" >
        </div>
    </div>
    <div id="show_income" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">一级提成</label>
            <div class="layui-input-block">
                <input type="number" name="income"  lay-verify="required"  value="{$info.income}" style="width: 150px !important;" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">

            <label class="layui-form-label">二级提成</label>
            <div class="layui-input-block">
                <input type="number" name="lower_income"  lay-verify="required"  value="{$info.lower_income}" style="width: 150px !important;" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="0" title="下架" >
            <input type="radio" name="status" checked value="1" title="上架" >


        </div>
    </div>
    <div class="layui-form-item" >
        <div class="layui-input-block">
            <input type="hidden" name="id" value="{$info.id}">
            <button type="button"  class="layui-btn" lay-submit=""  lay-filter="addEdit">保存</button>
        </div>
    </div>
</form>
<blockquote class="layui-elem-quote layui-quote-nm">

    <br>
</blockquote>
</body>
<script src="/static/uploadmore/upload.js" type="text/javascript"></script>
<script>



    function openfiexdincoe(val){
      if(val ==1){
          $('#show_income').show()
      }else {
          $('#show_income').hide()
      }

    }


    var multiple_images = [];

    //单击图片删除图片 【注册全局函数】

    function delMultipleImgs(this_img){

        //获取下标

        var subscript=$("#div-slide_show img").index(this_img);

        //删除图片

        this_img.remove();

        //删除数组

        multiple_images.splice(subscript, 1);

        //重新排序

        multiple_images.sort();

        $('.multiple_show_img').val(multiple_images);

        //返回

        return ;

    }

    var multiple_images1 = [];

    //单击图片删除图片 【注册全局函数】

    function delMultipleImgs1(this_img){

        //获取下标

        var subscript=$("#div-slide_show1 img").index(this_img);

        //删除图片

        this_img.remove();

        //删除数组

        multiple_images.splice(subscript, 1);

        //重新排序

        multiple_images.sort();

        $('.multiple_show_img1').val(multiple_images);

        //返回

        return ;

    }

    layui.config({
        base: "/static/uploadmore/"
    })

    layui.use(['form', 'layedit', 'laydate','jquery','upload'], function(){
        var form = layui.form
            ,layer = layui.layer
            , $ = layui.jquery
            , upload = layui.upload
            ,laydate = layui.laydate
            ,inputTags = layui.inputTags
        var layedit = layui.layedit;

        layedit.set({
            uploadImage: {
                url: '{:url(\'Upload/editUploadFile\')}' //接口url
                ,type: 'post' //默认post
            //     //{
            //     "code": 0 //0表示成功，其它失败
            //     ,"msg": "" //提示信息 //一般上传失败后返回
            //     ,"data": {
            //         "src": "图片路径"
            //         ,"title": "图片名称" //可选
            //     }
            // }
            }
        });
       var index= layedit.build('demo'); //建立编辑器


        layedit.sync(index)
//第一个参数：创建的富文本框实例
//第二个参数：之前存储的富文本内容（回显时查询得到）
//第三个参数：填写方式：true时为在已有的内容追加   false时为覆盖

        //拖拽上传
        upload.render({

            elem: '#multiple_img_upload'
            ,url: "{:url('Upload/ajaxUploadFile')}"
            ,multiple: true
            ,exts: 'png|jpeg|jpg|webp' //只允许上传压缩文件
            ,before: function(obj){

                //预读本地文件示例，不支持ie8

                obj.preview(function(index, file, result){

                    $('#div-slide_show').append('<img src="'+ result +'" alt="'+ file.name +'" title="点击删除" class="layui-upload-img" style="width: 100px;height: 100px;" onclick="delMultipleImgs(this)"> ')

                });

            }

            ,done: function(res){

                //如果上传成功

                if (res.code == 200) {

                    //追加图片成功追加文件名至图片容器

                    multiple_images.push(res.data.path);

                    $('.multiple_show_img').val(multiple_images);

                }else {

                    //提示信息

                    layer.msg(res.msg);

                }

            }

        });



        upload.render({

            elem: '#multiple_img_upload1'
            ,url: "{:url('Upload/ajaxUploadFile')}"
            ,multiple: true
            ,exts: 'png|jpeg|jpg|webp' //只允许上传压缩文件
            ,before: function(obj){

                //预读本地文件示例，不支持ie8

                obj.preview(function(index, file, result){

                    $('#div-slide_show1').append('<img src="'+ result +'" alt="'+ file.name +'" title="点击删除" class="layui-upload-img" style="width: 100px;height: 100px;" onclick="delMultipleImgs1(this)"> ')

                });

            }

            ,done: function(res){

                //如果上传成功

                if (res.code == 200) {

                    //追加图片成功追加文件名至图片容器

                    multiple_images.push(res.data.path);

                    $('.multiple_show_img1').val(multiple_images);

                }else {

                    //提示信息

                    layer.msg(res.msg);

                }

            }

        });
        upload.render(

            {
                elem: '#test5',
                field:'thumbs'
                ,url: "{:url('Upload/ajaxUpload')}"
                ,accept: 'file' //普通文件
                ,exts: 'png|jpeg|jpg|webp' //只允许上传压缩文件
                ,done: function(res){
                    if(res.code == 200){
                        // xadmin.close();
                        // xadmin.father_reload();
                        $('#thumb').show();
                        $('#prev_img').attr('src',''+res.data.path);
                        $('#thumbs').val(res.data.path);
                        layer.msg(res.msg);
                    }else {
                        layer.msg(res.msg);
                    }

                }
            });

        form.on('submit(addEdit)', function(data){
            var aa= layedit.getContent(index);
           var post = data.field
            post.content=aa
            $.post($('form').attr('action'),post,function(data){
                if(data.code == 200){
                    layer.msg(data.msg);
                    xadmin.close();
                    // xadmin.father_reload();
                }else {
                    layer.msg(data.msg);
                }
            });
            return false;
        });

    });

</script>


